#pragma once

//	draw ground plane
class CProteinVistaRenderer;
class CXTPPropertyGridItemVector3;

typedef struct {
	D3DXVECTOR3		pos;
	D3DXVECTOR3		normal;
	D3DCOLOR		diffuse;
} CLightVertex ,*pCLightVertex;

#define FVF_LIGHT_VERTEX		D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_DIFFUSE

class	CLightManager
{
public:
	CLightManager(CProteinVistaRenderer * pView = NULL);
	void SetProteinVistaRenderer(CProteinVistaRenderer * pView);

	virtual HRESULT OneTimeSceneInit()                         { return S_OK; }
	virtual HRESULT InitDeviceObjects();
	virtual HRESULT RestoreDeviceObjects();
	virtual HRESULT FrameMove();
	virtual HRESULT Render();
	virtual HRESULT InvalidateDeviceObjects();
	virtual HRESULT DeleteDeviceObjects();
	virtual HRESULT FinalCleanup();

	HRESULT HandleMessages ( HWND hWnd, UINT32 msg, WPARAM wParam, LPARAM lParam );

	void MakeWorldMatrix();
	HRESULT SetColor();
	HRESULT SetColor(COLORREF color);

	HRESULT RenderPovRay( CString & strPovRay );

	LPD3DXMESH	m_pMesh;
	D3DXCOLOR	m_lightColor;
	FLOAT		m_fovAngle;
	INT32		m_numSlice;
	FLOAT		m_minLightRadius;

	D3DXVECTOR3		GetLightPos();
	void			SetLightPos(D3DXVECTOR3 * pos);

	DOUBLE		GetRadius();
	D3DXVECTOR3 GetLightDirection();

	void		SetLightFOV(FLOAT angle);
	void		SetRadius(DOUBLE radius);
	void		SetLightDirection(D3DXVECTOR3 &direction);

	void		SetItemRadius(CXTPPropertyGridItemDouble * itemRadius);
	void		SetItemPosition(CXTPPropertyGridItemVector3 * itemPos);

	CXTPPropertyGridItemDouble	* m_pItemRadius;
	CXTPPropertyGridItemVector3 * m_pItemPosition;

	HRESULT		Save(CFile &file);
	HRESULT		Load(CFile &file);

	D3DXMATRIXA16	m_matWorld;	

private:
	CProteinVistaRenderer * m_pProteinVistaRenderer;

	D3DXVECTOR3		m_posLight;

	inline LPDIRECT3DDEVICE9 GetD3DDevice();

	BOOL			m_bDrag;
	INT32			m_posOldX;
	INT32			m_posOldY;
};

